using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DTO;

namespace DAO
{
    public class DataProvider
    {
        public OleDbConnection KetNoi()
        {
            string chuoiKetNoi = "Provider = Microsoft.Jet.Oledb.4.0 ; Data Source =QLKS.mdb";
            OleDbConnection boKetNoi = new OleDbConnection(chuoiKetNoi);
            boKetNoi.Open();
            return boKetNoi;
        }

        public DataTable DocCauTruc(string chuoilenh)
        {
            DataTable bang = new DataTable();
            OleDbConnection boKetNoi = KetNoi();
            OleDbDataAdapter boThichUng = new OleDbDataAdapter(chuoilenh, boKetNoi);
            boThichUng.FillSchema(bang, SchemaType.Source);
            boKetNoi.Close();
            return bang;
        }
        public DataTable DocBang(string chuoilenh)
        {
            DataTable bang = new DataTable();
            OleDbConnection boKetNoi = KetNoi();
            OleDbDataAdapter boThichUng = new OleDbDataAdapter(chuoilenh, boKetNoi);
            boThichUng.Fill(bang);
            boKetNoi.Close();
            return bang;
        }
        public void UpdateBang(string chuoilenh, DataTable bang)
        {
            OleDbConnection cn = KetNoi();
            OleDbDataAdapter boThichUng = new OleDbDataAdapter(chuoilenh, cn);
            OleDbCommandBuilder boPhatSinh = new OleDbCommandBuilder(boThichUng);
            boThichUng.Update(bang);
            cn.Close();
        }
    }
}
